/**
 * url： https://101.zoo.team/zi-fu-chuan/zi-fu-chuan-part-2-bao-shu-fan-zhuan-zi-fu-chuan-he-zi-fu-chuan-zhong-de-di-yi-ge-wei-yi-zi-fu#fan-zhuan-zi-fu-chuan
 * 
 * 将输入的字符串反转过来。 输入字符串以字符数组char[]的形式给出。
 * PS： 不要给另外的数组分配额外的空间，必须原地修改输入数组，使用 O(1) 的额外空间解决这一问题
 * 
 * 示例1：
 * 输入：["h","e","l","l","o"]
 * 输出：["o","l","l","e","h"]
 * 
 * 示例2：
 * 输入：["H","a","n","n","a","h"]
 * 输出：["h","a","n","n","a","H"]
 * 
 * 
 */

/**
 * 首尾替换
 * 使用ES6的构造函数
 */

const reverseString1 = (arr) => {
    const len = arr.length
    for (let i = 0 ; i < (len/2 - 1) ; i++) {
        [arr[i], arr[len-i-1]] = [arr[len-i-1], arr[i]]
    }
    return arr
}

/**
 * 中间量替换
 */
const reverseString2 = (arr) => {
    const len = arr.length
    for (let i = 0 ; i < (len/2 - 1) ; i++) {
        const a = arr[i]
        arr[i] = arr[len - i -1]
        arr[len - i - 1] = a;
    }
    return arr
}

